<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;

        margin: 0;
      }

      li {
        list-style: none;
        width: 100px;
        text-align: center;
        border: 1px solid rebeccapurple;
        margin-left: 10px;
        float: left;
        cursor: pointer;
      }

      #tabCon {
        clear: both;
      }

      #tabCon div {
        display: none;
        font-size: 30px;
        width: 500px;
        text-align: center;
      
      }

      #tabCon div.fdiv {
        display: block;
      }
       .active{
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div id="tanContainer">
      <div id="tab">
        <ul>
          <li class="fli">标题一</li>

          <li>标题二</li>

          <li>标题三</li>

          <li>标题四</li>
        </ul>
      </div>

      <div id="tabCon">
        <div class="fdiv">内容一</div>

        <div>内容二</div>

        <div>内容三</div>

        <div>内容四</div>
      </div>
    </div>
    <script>
     let lis=   document.querySelectorAll("ul li")
    let divs=    document.querySelectorAll("#tabCon>div")
      for(let i=0; i<lis.length; i++){
        lis[i].setAttribute("index",i)
        lis[i].onclick=function(){
            for(let j=0; j<lis.length; j++){
                lis[j].classList.remove("active")
                divs[j].classList.remove("fdiv")
            }
         this.classList.add("active")
          let index=  this.getAttribute("index")
           console.log(index)
           divs[index].classList.add("fdiv")
        }
     }

     console.log(divs);
    </script>
  </body>
</html>
